<?php
class SearchAction extends BaseAction
{
    public function index()
    {
        $q = I('get.q');
        $this->checkEmpty($q, '关键字必须给出！');
        $CourseModel = D('Course');

        $map = array();
        $map['title'] = array('like', '%' . $q . '%');
        $map['description'] = array('like', '%' . $q . '%');
        $where['_logic'] = 'or';
        
        $count = $CourseModel->where($map)->count();
        $Page = parent::getPage($count);
        $items = $CourseModel->where($map)->limit($Page['limit'])->select();
        $this->assign('items', $items);
        $this->assign('page', $Page['page']);
        $this->display();
    }
}